<?php
FLEA::loadClass('Controller_Base');
class Controller_JRBlocks extends Controller_Base {
	var $_modelBlocks;
	function Controller_JRBlocks() {
		parent::Controller_Base();
		$this->_modelBlocks =& FLEA::getSingleton('Model_Blocks');
	}
/*显示版块列表*/
	function actionIndex() {
		$blocks = $this->_modelBlocks->findAll();
		include(TPL_DIR."/blockslist.php");
	}
/*显示某一版块子栏目列表*/
	function actionSubIndex() {
		//TODO
		$id = $_POST["id"];
		$blocks = $this->_modelBlocks->findByKey();
	}
/*创建一个新的栏目*/
	function actionCreateBlock() {
		//Todo
		$bid = $_POST["id"];
		$pid = $_POST["parent"];
		$name = $_POST["blockname"];
		$desc = $_POST["blockdesc"];
		//$firstman = $_SESSION["jiraa"]["email"];
		$firstman = "jiangsujier@gmail.com";
		if($this->_modelBlocks->findCount(array("bid"=>$bid)) == 0) {
			$newblock =array(
				"name"=>$name,
				"desc"=>$desc,
				"firstman"=>$firstman
			);
			$this->_modelBlocks->create($newblock);
		} else {
			$old_block = $this->_modelBlocks->findByField("bid",$bid);
			$old_block["name"]=$name;
			$old_block["desc"] = $desc;
			$this->_modelBlocks->update($old_block);
		}
	}
	function actionDeleteBlock() {
//		$bid = $_POST["id"];
//		$this->_modelBlocks->removeByPkv($bid);

	}
}
?>